package com.combetter.changxing.adapter;

import android.bluetooth.BluetoothDevice;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.combetter.changxing.R;
import com.combetter.changxing.collections.PerfectClickListener;
import com.combetter.changxing.util.Check;

import java.util.List;

/**
 * 类名  蓝牙搜索的设备列表Adapter
 * 作者  tlfx: Sean.guo
 * 日期  2019/3/16 17:12
 */
public class FacilityListAdapter extends BaseQuickAdapter<BluetoothDevice, BaseViewHolder> {

    private FacilityListInterface mClick;

    public void setFacilityListClickListener(FacilityListInterface click) {
        this.mClick = click;
    }

    public FacilityListAdapter(@Nullable List<BluetoothDevice> data) {
        super(R.layout.fragment_facility_list_item, data);
    }

    public void clearAllData() {
        if (this.getData() != null && getData().size() > 0) {
            this.getData().clear();
        }
        notifyDataSetChanged();
    }
    @Override
    protected void convert(BaseViewHolder helper, BluetoothDevice item) {
        if (!Check.isEmpty(item.getName())) {
            helper.setText(R.id.tv_name, item.getName());
        }

        helper.getView(R.id.tv_add).setOnClickListener(new PerfectClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if (mClick != null) {
                    mClick.viewAdd(item);
                }
            }
        });
    }

    public interface FacilityListInterface {
        void viewAdd( BluetoothDevice item);
    }
}
